package fanjingzhu.check.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import publics.model.Proposer;
import publics.util.Page;
import fanjingzhu.check.dao.ProposerDao;
import fanjingzhu.check.service.ProposerService;

@Component("proposerService")
public class ProposerServiceImpl implements ProposerService{
	
	ProposerDao proposerDao;
	  
	  public ProposerDao geProposerDao() {
				return proposerDao;
	  }
	  @Resource(name="proposerDao")
	   public void setProposerDao(ProposerDao proposerDao) {
				this.proposerDao = proposerDao;
				System.out.println("proposerDaoImpl inject in ProposerServiceImpl");
	  }  
	  public Object saveProposer(Proposer proposer) {
			return this.proposerDao.save(proposer);
		}
	  
	public boolean deleteProposer(Integer proposerId) {
		return this.proposerDao.deleteById(proposerId);
	}
	
	public boolean updateProposer(Proposer proposer) throws Exception {
		return	this.proposerDao.update(proposer);
	
	}
	
	public List findById(int proposerId) {
		List ls= new ArrayList();		
		ls.add(proposerDao.findById(proposerId));
		return ls;
	}

	public Page findByPage(Page page) {
		String sql = "from Proposer ";
		System.out.println("sql ="+sql);// 测试用，请观察拼接出的sql语句，加强理解
		
		int pageSize = page.getLimit();
		int offset = page.getStart();//-1)*pageSize;
		page.setRoot(proposerDao.findByPage(sql,offset,pageSize));//把查询结果放入root中
		page.setTotalProperty(proposerDao.findByCount(sql));   //、把数据总数放入totalProperty中
		return page;
	}
}
